﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_bid_project_product_bidTable_listChild : System.Web.UI.Page, HZ.MBSM.BLL.IPageDescribe 
{
    public string ProjectId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string BidNum, strSql;
        labProjectId.Visible = false;

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                lstDY.Items.Add("全部");
                lstDY.Items.Add("已对应");
                lstDY.Items.Add("未对应");

                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account != null)
                {
                    Int64 AccountId = SysFun.ToLong(_Account.AccountId);

                    Db db = new Db();
                    strSql = "select projectid,ProjectMarker,Title from project where accountid in (select accountid_father from dbo.AgencyChild where accountid=" + AccountId.ToString() + ")";
                    System.Data.IDataReader dr = db.DataReader(strSql);
                    listProject.DataSource = dr;
                    listProject.DataTextField = "Title";
                    listProject.DataValueField = "projectid";
                    listProject.DataBind();
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                    ProjectId = listProject.SelectedValue;
                }
            }
            if (Request.Form["SaveId"] == "保存编号")
            {
                foreach (string strId in SysFun.ToTrim(Request.Form["hiddenId"]).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                {
                    BidNum = SysFun.ToTrim(Request.Form["txt" + strId]);
                    if (BidNum != "")
                    {
                        Db db1 = new Db();
                        strSql = "update bid_project_product set BidNum='" + BidNum + "' WHERE Id=" + strId;
                        db1.Command(strSql);
                        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "bid_project_product", strSql, "../Agency/bid_project_product_bidTable_listChild.aspx");
                        db1.Close();
                    }
                }
            }
            show();
            
        }
    }

    public void show()
    {
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' class=table_table cellSpacing=1 cellPadding=2  align=center border=0><tr><td class='table_title'>品目号</td><td class='table_title'>招标通用名</td><td class='table_title'>招标剂型</td><td class='table_title'>招标规格</td><td class='table_title'>通用名</td><td class='table_title'>剂 型</td><td class='table_title'>规 格</td><td class='table_title'>单 位</td><td class='table_title'>招标编码</td><td class='table_title'>修改</td></tr>");
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bid_project_product_bidTable";                                               //要查询的表明
        dbPage.Key = "Id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "Id,ProjectId,ProductId,ProductName,Medicinemodel,Outlookc,Unit,BidTableId,BidTableName,BidTableType,BidTableOutlookc,ProductCode,BidNum";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "ProductName,Medicinemodel,Outlookc";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        int i = 0;
        while (dr.Read())
        {
            i += 1;
            if (i % 2 == 0)
            {
                strHtml.Append("<tr class='table_td'>");
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
            }
            strHtml.Append("<td ><input type='hidden' name='hiddenId' value='" + dr["Id"].ToString() + "'/>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableType"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableOutlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Unit"].ToString() + "</td>");
            strHtml.Append("<td><input type=text style='width=70'  value='" + dr["BidNum"].ToString() + "' name ='txt" + dr["Id"].ToString() + "' onblur=\"javascript:if(!/^[A-Za-z0-9]+$/.test(this.value)){alert('品目号只能由数字和英文字母组成！');return false;}\"/></td>");
            strHtml.Append(" <td><a target='_blank' href='bid_project_product_bidTable_Add.aspx?ProjectId=" + ProjectId + "&Id=" + dr["Id"].ToString() + "&ProductId=" + dr["ProductId"].ToString() + "'>修改</a></td>");
            strHtml.Append("</tr>");

        }
        strHtml.Append("</table>");
        Label9.Text = strHtml.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, ProductName, Medicinemodel, Outlookc, BidTableName, BidTableType, BidTableOutlookc, ProductCode, BidNum,DY;
        ProjectId = listProject.SelectedValue;
        ProductName = txtProductName.Text.ToString().Trim(); 
        Medicinemodel = txtMedicinemodel.Text.ToString().Trim();
        Outlookc = txtOutlookc.Text.ToString().Trim();
        BidTableName = txtBidTableName.Text.ToString().Trim();
        BidTableOutlookc = txtBidTableOutlookc.Text.ToString().Trim();
        BidTableType = txtBidTableType.Text.ToString().Trim();
        ProductCode = txtProductCode.Text.ToString().Trim();
        BidNum = txtBidNum.Text.ToString().Trim();
        strtemp = " ProjectId=" + ProjectId + " and";
        DY = lstDY.SelectedValue;
        switch (DY)
        {
            case "全部":
                break;
            case "已对应":
                strtemp += " BidTableName is not null and";
                break;
            case "未对应":
                strtemp += " BidTableName is null and";
                break;
        } 

        if (ProductName != "")
        {
            strtemp = strtemp + " (ProductName like '%" + ProductName + "%' or " + " SpellingCode like '%" + ProductName + "%') and";
        }
        if (Medicinemodel != "")
        {
            strtemp = strtemp + " Medicinemodel like '%" + Medicinemodel + "%' and";
        }
        if (Outlookc != "")
        {
            strtemp = strtemp + " Outlookc like '%" + Outlookc + "%' and";
        }
        if (BidTableName != "")
        {
            strtemp = strtemp + " BidTableName like '%" + BidTableName + "%' and";
        }
        if (BidTableType != "")
        {
            strtemp = strtemp + " BidTableType like '%" + BidTableType + "%' and";
        }
        if (BidTableOutlookc != "")
        {
            strtemp = strtemp + " BidTableOutlookc like '%" + BidTableOutlookc + "%' and";
        }
        if (ProductCode != "")
        {
            strtemp = strtemp + " ProductCode like '%" + ProductCode + "%' and";
        }
        if (BidNum != "")
        {
            strtemp = strtemp + " BidNum like '%" + BidNum + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }



    #region IPageDescribe 成员

    public string Name
    {
        get { return "招标目录维护"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "招标目录管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
            return _AccountType;
        }
    }

    #endregion
}
